/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */

var ajaxLoadingPopupStatus = 0;
//loading popup with jQuery magic!
function loadAjaxLoadingPopup(imgId, divBgId){
    //loads popup only if it is disabled
    if(ajaxLoadingPopupStatus==0){
        centerAjaxLoadingPopup(imgId, divBgId);
        $(divBgId).css({
            "opacity": "0.5"
        });
        $(divBgId).fadeIn("fast");
        $(imgId).fadeIn("fast");
        ajaxLoadingPopupStatus = 1;
		
    }
}

//disabling popup with jQuery magic!
function disableAjaxLoadingPopup(imgId, divBgId){
    //disables popup only if it is enabled
    if(ajaxLoadingPopupStatus==1){
        $(divBgId).fadeOut();
        $(divBgId).hide();
		
        ajaxLoadingPopupStatus = 0;
    }
    $(imgId).hide();
}

function centerAjaxLoadingPopup(imgId, divBgId){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var bodywidth = $('body').innerWidth();
	var bodyheight = $('body').innerHeight();
	var popupHeight = $(imgId).height();
	var popupWidth = $(imgId).width();
	
	var wpos = (bodywidth > windowWidth) ? bodywidth : windowWidth;
	var hpos = (bodyheight > windowHeight) ? bodyheight : windowHeight;
	var scrollWindow = $(window).scrollTop();
	var top = windowHeight/2-((popupHeight/3)*2) + scrollWindow;
	var left = windowWidth/2-popupWidth/2;
	
	//centering
	$(imgId).css({
		"position": "absolute",
		"top": top,
		"left": left
	});
	//only need force for IE6
	$(divBgId).css({
		"height": hpos,
		"width" : wpos
	});

	$(window).scroll(function(){		
		if($(imgId).css('display') != 'none')
		{
			$(imgId).stop();
			var scroll = $(window).scrollTop();
			var scrollPos = windowHeight/2-((popupHeight/3)*2) + scroll;
			$(imgId).animate({top: scrollPos},'slow');
		}
	});
}

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}



